package com.woniuxy.gobang.ui;
import dao.UserDataDAO;
import entity.User;
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;

public class MainUI extends Application {

	public MainUI() {

	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		// 为窗体设置标题
		primaryStage.setTitle("蜗牛五子棋");
		// 设置窗体大小不可调整
		primaryStage.setResizable(false);
		// 创建面板
		Pane pane = new Pane();
//		// 设置背景颜色
//		pane.setBackground(new Background(new BackgroundFill(Color.BLANCHEDALMOND, null, null)));

		// 添加单机版按钮
		Button singleBtn = new Button("单机版");
		singleBtn.setPrefSize(100, 50);
		singleBtn.setLayoutX(50);
		singleBtn.setLayoutY(50);
		pane.getChildren().add(singleBtn);
		// 单机版按钮事件
		singleBtn.setOnMouseClicked(new EventHandler<Event>() {
			@Override
			public void handle(Event event) {
				new SingleModeStage();
				primaryStage.close();
			}
		});

		// 添加对战版按钮
		Button battleBtn = new Button("对战版");
		battleBtn.setPrefSize(100, 50);
		battleBtn.setLayoutX(200);
		battleBtn.setLayoutY(50);
		pane.getChildren().add(battleBtn);
		//对战版按钮事件
		battleBtn.setOnMouseClicked(new EventHandler<Event>() {
			@Override
			public void handle(Event event) {
				Global.logonStage = new LogOnStage();
				primaryStage.close();
			}
		});
		// 创建一个场景对象
		Scene scene = new Scene(pane, 350, 150);// 控制窗体尺寸
		// 将场景添加到窗体上
		primaryStage.setScene(scene);

		// 将线条添加到面板
		primaryStage.show();
		
		primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
            @Override
            public void handle(WindowEvent event) {
                System.exit(0);
            }
        });
	}

	public static void main(String[] args) {
		launch(args);
	}
}
